﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using cadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System.IO;

namespace YNCNumberSys
{
    /// <summary>
    /// 加载在AutoCAD中的工具条，工具条上有各个命令的入口。
    /// </summary>
    public partial class AcadToolBarPalette : UserControl
    {
        public AcadToolBarPalette()
        {
            InitializeComponent();
        }

        private bool m_登录;

        public bool b_登录
        {
            get { return m_登录; }
            set 
            { 
                m_登录 = value;
                this.btn_登录.Enabled = value;
            }
        }

        private bool m_退出;

        public bool b_退出
        {
            get { return m_退出; }
            set 
            { 
                m_退出 = value;
                this.btn_退出.Enabled = value;
            }
        }

        private bool m_修改密码;

        public bool b_修改密码
        {
            get { return m_修改密码; }
            set 
            { 
                m_修改密码 = value;
                this.btn_修改密码.Enabled = value;
            }
        }

        private bool m_用户管理;

        public bool b_用户管理
        {
            get { return m_用户管理; }
            set 
            {
                m_用户管理 = value;
                this.btn_用户管理.Enabled = value;
                this.btn_用户管理.Visible = value;
            }
        }

        private bool m_初始设置;

        public bool b_初始设置
        {
            get { return m_初始设置; }
            set 
            {
                m_初始设置 = value;
                this.btn_初始设置.Enabled = value;
                this.btn_初始设置.Visible = value;
            }
        }

        private bool m_申请图号;

        public bool b_申请图号
        {
            get { return m_申请图号; }
            set 
            { 
                m_申请图号 = value;
                this.btn_申请图号.Enabled = value;
            }
        }

        private bool m_图号管理;

        public bool b_图号管理
        {
            get { return m_图号管理; }
            set
            {
                m_图号管理 = value;
                this.btn_图号管理.Enabled = value;
                //this.btn_图号管理.Visible = value;
            }
        }
        private bool m_4C有图申请;

        public bool b_4C有图申请
        {
            get { return m_4C有图申请; }
            set
            {
                m_4C有图申请 = value;
                this.btn_4C有图申请.Enabled = value;
            }
        }

        private bool m_4C无图申请;

        public bool b_4C无图申请
        {
            get { return m_4C无图申请; }
            set
            {
                m_4C无图申请 = value;
                this.btn_4C无图申请.Enabled = value;
            }
        }

        private bool m_单个文件申请;

        public bool b_单个文件申请
        {
            get { return m_单个文件申请; }
            set 
            { 
                m_单个文件申请 = value;
                this.btn_单个文件申请.Enabled = value;
            }
        }

        private bool m_图号查询;

        public bool b_图号查询
        {
            get { return m_图号查询; }
            set
            {
                m_图号查询 = value;
                this.btn_图号查询.Enabled = value;
            }
        }

        private bool m_外协图号申请;

        public bool b_外协图号申请
        {
            get { return m_外协图号申请; }
            set
            {
                m_外协图号申请 = value;
                this.btn_外协图号申请.Enabled = value;
            }
        }

        private string m_s机床;
        public string s机床
        {
            get { return m_s机床; }
            set
            {
                m_s机床 = value;
            }
        }
        private string m_A号;
        public string A号
        {
            get { return m_A号; }
            set
            {
                m_A号 = value;
            }
        }
        private bool m_statistics;
        public bool b_Statistics
        {
            get { return m_statistics; }
            set { m_statistics = value;
                toolStripButtonAns.Visible = value;
                toolStripButtonAns.Enabled = value;
            }
        }
        /// <summary>
        /// 登录。登录前默认图纸打开。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_登录_Click(object sender, EventArgs e)
        {
            
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("LOGIN ", true, false, true);
        }
        /// <summary>
        /// 退出当前用户。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_退出_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("LOGOUT ", true, false, true);
        }
        /// <summary>
        /// 修改密码的命令调用。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_修改密码_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("PASSWORD ", true, false, true);
        }
        /// <summary>
        /// INITUSER 用户管理。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_用户管理_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("INITUSER ", true, false, true);
        }
        /// <summary>
        /// 初始设置。缺省的设置？
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_初始设置_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("INITSYSTEM ", true, false, true);
        }
        /// <summary>
        /// APPLYNUMBER 申请图号。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_申请图号_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("APPLYNUMBER ", true, false, true);
        }

        private void btn_图号管理_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("NUMBERMANAGEMENT ", true, false, true);
        }

        private void btn_4C有图申请_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("APPLY4CNUMBER ", true, false, true);
        }

        private void btn_4C无图申请_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("APPLY4CNUMBERNODWG ", true, false, true);
        }

        private void btn_图号查询_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("NUMBERQUERY ", true, false, true);
        }

        private void btn_外协图号申请_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("APPLYOUT ", true, false, true);
        }

        private void btn_单个文件申请_Click(object sender, EventArgs e)
        {
            if (cadApp.DocumentManager.Count == 0)
            {
                cadApp.ShowAlertDialog("请先新建图纸!");
                return;
            }
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("APPLYSINGLE ", true, false, true);
        }

        private void toolStripButtonAbout_Click(object sender, EventArgs e)
        {

            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("ABOUTRP ", true, false, true);
        }

        private void toolStripButtonAns_Click(object sender, EventArgs e)
        {
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("STATISTICS ", true, false, true);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            cadApp.DocumentManager.MdiActiveDocument.SendStringToExecute("Test ", true, false, true);
        }
    }
}
